log using results.log, replace
**Install packages required for analyses and plotting**
ssc install estout, replace
ssc install ranktest,replace
ssc install coefplot, replace
ssc install reghdfe,replace

clear all
********************************************************************************
**************** Descriptive graphs (Figure 1-2) *******************************
********************************************************************************

use "data_fig1_2.dta", clear


twoway (connected democbest_coh birth_10, msymbol(circle) msize(vsmall) mcolor(gs6) lcolor(gs10) lwidth(thick)) ///
if region_fe==1 |region_fe==2 ///
, ///
xlabel(1900(30)1990, labsize(vlarge) angle(45)) ///
ylabel(50(10)100, labsize(med) labcolor(black) glcolor(black%8)) ///
xtitle("Cohort", size(small) color(black)) ytitle("Democratic support (%)" , size(small) color(black)) ///
by(, legend(off)) ///
by(, graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))) ///
by(COUNTRY_DATA, note("") cols(8)) subtitle(, color(black) nobox size(med)) ///
xsize(15) ysize(20) 

graph save figure1,  replace


twoway (connected democbest_coh birth_10, msymbol(circle) msize(vsmall) mcolor(gs6) lcolor(gs10) lwidth(thick)) ///
if region_fe==4 |region_fe==5 ///
, ///
xlabel(1900(30)1990, labsize(vlarge) angle(45)) ///
ylabel(50(10)100, labsize(med) labcolor(black) glcolor(black%8)) ///
xtitle("Cohort", size(small) color(black)) ytitle("Democratic support (%)" , size(small) color(black)) ///
by(, legend(off)) ///
by(, graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))) ///
by(COUNTRY_DATA, note("") cols(8)) subtitle(, color(black) nobox size(med)) ///
xsize(15) ysize(20) 

graph save figure2, replace




********************************************************************************
******************************** MAIN ANALYSIS *********************************
********************************************************************************
** Table 1 and Figure 3 **
use "data_main.dta", replace

eststo clear

* Cohort, Age, Year, and Country FE (no interaction) *
reghdfe democbest c.gdp_growth_1010_18_28 c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)

eststo

* Cohort, Age, Year, and Country FE *
reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)

eststo

* Cohort, Age, Year, and Country RE *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., re r
eststo

* Cohort, Age, Year, and Country FE + current economic growth *
reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 c.gdp_growth##c.democracy_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
eststo

* Cohort, Age, Year, and Country FE + current regime *
reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 democracy i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
eststo

* Cohort, Age, Year, and Country FE + individual-level controls *
reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 female married i.educ i.religion i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
eststo

reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 c.gdp_growth##c.democracy_1010_18_28 democracy female married i.educ i.religion i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
eststo



esttab, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(*.birth_10 *.age_10 *.YEAR_DATA) eqlabels(none) nonumbers compress

esttab using table1.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(*.birth_10 *.age_10 *.YEAR_DATA female married *.educ *.religion) eqlabels(none) nonumbers compress

//comparison to impact of current growth
reghdfe democbest gdp_growth_20 c.gdp_growth_1010_18_28 c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy==1, cluster(ccohort) absorb(COUNTRY_ID)

** Figure 3 **
* Predicted probabilitites democracy *

reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)

margins, at(gdp_growth_1010_18_28 = (-6(1)8) democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(circle) msize(medium)) ciopts(color(gs10%30) lcolor(gs10%30) lwidth(none)) recastci(rarea) ///
plot2opts(mcolor(black) lpattern(solid) lcolor(black) msymbol(circle_hollow) msize(medium)) ci2opts(color(gs10%30) lcolor(gs10%30))  ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) legend(order(3 "Autocracies" 4 "Democracies") region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.6) symysize(*.6) forcesize ring(0) position(11) colgap(tiny) row(1)) ///
xlabel(-6(1)8, nogrid labsize(medsmall)) ///
xtitle("Economic performance (early adulthood)", margin(large) size(med)) title("") ytitle("Support democracy", size(medsmall) margin(small)) ///
addplot((histogram gdp_growth_1010_18_28 if e(sample) & gdp_growth_1010_18_28>=-6 & gdp_growth_1010_18_28<=8,  ///
ytitle("Support democracy", size(medsmall) margin(small)) discrete width(.5) freq yaxis(2) xlabel(-6(1)8, nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 100000, nolabels noticks axis(2)) legend(order(3 "Autocracies" 4 "Democracies") region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.8) symysize(*.8) forcesize ring(0) position(11) colgap(tiny) row(1)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save dem_pred, replace


* Marginal effects democracy *
reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
margins, dydx(gdp_growth_1010_18_28) at(democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(med) margin(small)) ///
addplot((histogram democracy_1010_18_28 if e(sample),xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save dem_marg, replace

graph combine dem_pred.gph dem_marg.gph, xsize(20) ysize(10) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) rows(1) cols(2) 

graph save figure3,  replace


** Figure 4: Other periods **
eststo m1: qui reghdfe democbest   c.gdp_growth_710_10_17##c.democracy_710_10_17 gdp_ln_710_10_17 population_gled_ln_710_10_17  i.birth_10 i.age_10 i.YEAR_DATA if age >=18 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
qui margins, dydx(gdp_growth_710_10_17) at(democracy_710_10_17 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (ages 10-17)", margin(large) size(med)) title("") ytitle("Effect of economic performance (ages 10-17)", size(med) margin(small)) ///
addplot((histogram democracy_710_10_17 if e(sample),  xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (ages 10-17)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(med)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save period1, replace

eststo m3: qui reghdfe democbest   c.gdp_growth_510_29_34##c.democracy_510_29_34 gdp_ln_510_29_34 population_gled_ln_510_29_34  i.birth_10 i.age_10 i.YEAR_DATA if age >=35 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
qui margins, dydx(gdp_growth_510_29_34) at(democracy_510_29_34 = (0 1)) level(95) asobserved 
marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (ages 29-34)", margin(large) size(med)) title("") ytitle("Effect of economic performance (ages 29-34)", size(med) margin(small)) ///
addplot((histogram democracy_510_29_34 if e(sample),  xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (ages 29-34)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(med)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save period3, replace
graph combine period1.gph period3.gph, xsize(20) ysize(10) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) rows(1) cols(2) 

graph save figure4,  replace



********************************************************************************
***************************** PERSISTENCE ANALYSIS *****************************
********************************************************************************
** Figure 5 **
reghdfe democbest c.gdp_growth_1010_18_28##c.age gdp_ln_1010_18_28 population_gled_ln_1010_18_28   if age >=35 & age !=. & democracy_1010_18_28==1, absorb(COUNTRY_ID YEAR_DATA birth_10) cluster(ccohort)
eststo Democracy: margins, dydx(gdp_growth) at( age=(35 (5) 70) ) post
reghdfe democbest c.gdp_growth_1010_18_28##c.age gdp_ln_1010_18_28 population_gled_ln_1010_18_28   if age >=35 & age !=. & democracy_1010_18_28==0, absorb(COUNTRY_ID YEAR_DATA birth_10) cluster(ccohort)
eststo Autocracy: margins, dydx(gdp_growth) at( age=(35 (5) 70) ) post

coefplot ///
(Democracy, offset(0.0) mcolor(black) lpattern(solid) lcolor(black) msymbol(circle_hollow) msize(medium) ciopts(color(black) lcolor(black))) ///
(Autocracy, offset(0.0) mcolor(black) lpattern(solid) lcolor(black) msymbol(circle) msize(medium) ciopts(color(black) lcolor(black))) ///
, ///
vertical ///
yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) ///
ylabel(-1(0.25)1, nogrid labsize(medsmall)) ytitle(" Effect of economic performance (early adulthood)", margin(small) color(black) size(med)) graphregion(lstyle(none) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
xlabel( 1 "35" 2 "40" 3 "45" 4 "50" 5 "55" 6 "60" 7 "65" 8 "70", labsize(medsmall) nogrid) xtitle("Age", margin(small) color(black) size(med)) ///
legend(order(4 "Autocracies" 2 "Democracies" ) region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.8) symysize(*.8) forcesize ring(0) position(11) colgap(tiny) row(1)) 

graph save figure5, replace





********************************************************************************
***************************** Online Appendix      *****************************
********************************************************************************

** Standard Errors Clustered on country **

eststo clear
* Cohort, Age, Year, and Country FE (no interaction) *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28 c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., fe r
eststo
* Cohort, Age, Year, and Country FE *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., fe r
eststo

* Cohort, Age, Year, and Country RE *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., re r
eststo

* Cohort, Age, Year, and Country FE + current economic growth *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 c.gdp_growth##c.democracy_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., fe r
eststo
* Cohort, Age, Year, and Country FE + current regime *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 democracy i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., fe r
eststo
* Cohort, Age, Year, and Country FE + individual-level controls *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 female married i.educ i.religion i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., fe r
eststo

esttab, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(*.birth_10 *.age_10 *.YEAR_DATA) eqlabels(none) nonumbers compress
esttab using tableA2.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(*.birth_10 *.age_10 *.YEAR_DATA female married *.educ *.religion) eqlabels(none) nonumbers compress


** Alt. growth measure **
reghdfe democbest c.growth_pwt_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
margins, dydx(growth_pwt_1010_18_28) at(democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(med) margin(small)) ///
addplot((histogram democracy_1010_18_28 if e(sample),xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save figureA1, replace

** Alt. econ performance measure **
reghdfe democbest c.div_gdp_5_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
margins, dydx(div_gdp_5_1010_18_28) at(democracy_1010_18_28=(0 1))


marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(med) margin(small)) ///
addplot((histogram democracy_1010_18_28 if e(sample),xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save figureA2, replace



** Alt. age cut-offs **
xtset COUNTRY_ID
eststo m0: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=29 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m1: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=30 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m2: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=31 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m3: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=32 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m4: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=33 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m5: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=34 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m6: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m7: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=36 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m8: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=37 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m9: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=38 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m10: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=39 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m11: qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=40 & age !=., absorb(COUNTRY_ID) cluster(ccohort)


esttab m0 m1 m2 m3 m4 m5  , replace label b(3) se(3) se star( * 0.05 ) keep(gdp_growth_1010_18_28 c.gdp_growth_1010_18_28#c.democracy_1010_18_28) eqlabels(none) nonumbers compress
esttab m0 m1 m2 m3 m4 m5  using tableA3upper.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) keep(gdp_growth_1010_18_28 c.gdp_growth_1010_18_28#c.democracy_1010_18_28) eqlabels(none) nonumbers compress
esttab m6 m7 m8 m9 m10 m11 , replace label b(3) se(3) se star( * 0.05 ) keep(gdp_growth_1010_18_28 c.gdp_growth_1010_18_28#c.democracy_1010_18_28) eqlabels(none) nonumbers compress
esttab m6 m7 m8 m9 m10 m11 using tableA3lower.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) keep(gdp_growth_1010_18_28 c.gdp_growth_1010_18_28#c.democracy_1010_18_28) eqlabels(none) nonumbers compress



** Other periods in life **

eststo m1: qui reghdfe democbest   c.gdp_growth_710_10_17##c.democracy_710_10_17 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m2: qui reghdfe democbest   c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., absorb(COUNTRY_ID) cluster(ccohort)
eststo m3: qui reghdfe democbest   c.gdp_growth_510_29_34##c.democracy_510_29_34 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., absorb(COUNTRY_ID) cluster(ccohort)

esttab m1 m2 m3 using tableA4.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) keep(gdp_growth* c.gdp_growth*) eqlabels(none) nonumbers 


** Age interval graph **
qui reghdfe democbest c.gdp_growth_410_8_12##c.democracy_410_8_12 gdp_ln_410_8_12 population_gled_ln_410_8_12 i.birth_10  i.YEAR_DATA if age >=12 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m0: qui margins, dydx(gdp_growth_410_8_12) at(democracy_410_8_12=( 1)) post
qui reghdfe democbest c.gdp_growth_410_8_12##c.democracy_410_8_12 gdp_ln_410_8_12 population_gled_ln_410_8_12 i.birth_10  i.YEAR_DATA if age >=12 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m0a: qui margins, dydx(gdp_growth_410_8_12) at(democracy_410_8_12=( 0)) post
qui reghdfe democbest c.gdp_growth_410_13_17##c.democracy_410_13_17 gdp_ln_410_13_17 population_gled_ln_410_13_17 i.birth_10  i.YEAR_DATA if age >=17 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m1: qui margins, dydx(gdp_growth_410_13_17) at(democracy_410_13_17=( 1)) post
qui reghdfe democbest c.gdp_growth_410_13_17##c.democracy_410_13_17 gdp_ln_410_13_17 population_gled_ln_410_13_17 i.birth_10  i.YEAR_DATA if age >=17 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m1a: qui margins, dydx(gdp_growth_410_13_17) at(democracy_410_13_17=( 0)) post
qui reghdfe democbest c.gdp_growth_410_18_22##c.democracy_410_18_22 gdp_ln_410_18_22 population_gled_ln_410_18_22 i.birth_10  i.YEAR_DATA if age >=18 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m2: qui margins, dydx(gdp_growth_410_18_22) at(democracy_410_18_22=( 1)) post
qui reghdfe democbest c.gdp_growth_410_18_22##c.democracy_410_18_22 gdp_ln_410_18_22 population_gled_ln_410_18_22 i.birth_10  i.YEAR_DATA if age >=18 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m2a: qui margins, dydx(gdp_growth_410_18_22) at(democracy_410_18_22=( 0)) post
qui reghdfe democbest c.gdp_growth_410_23_27##c.democracy_410_23_27 gdp_ln_410_23_27 population_gled_ln_410_23_27 i.birth_10  i.YEAR_DATA if age >=27 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m3: qui margins, dydx(gdp_growth_410_23_27) at(democracy_410_23_27=( 1)) post
qui reghdfe democbest c.gdp_growth_410_23_27##c.democracy_410_23_27 gdp_ln_410_23_27 population_gled_ln_410_23_27 i.birth_10  i.YEAR_DATA if age >=27 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m3a: qui margins, dydx(gdp_growth_410_23_27) at(democracy_410_23_27=( 0)) post
qui reghdfe democbest c.gdp_growth_410_28_32##c.democracy_410_28_32 gdp_ln_410_28_32 population_gled_ln_410_28_32 i.birth_10  i.YEAR_DATA if age >=32 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m4: qui margins, dydx(gdp_growth_410_28_32) at(democracy_410_28_32=( 1)) post
qui reghdfe democbest c.gdp_growth_410_28_32##c.democracy_410_28_32 gdp_ln_410_28_32 population_gled_ln_410_28_32 i.birth_10  i.YEAR_DATA if age >=32 & age !=. , absorb(COUNTRY_ID) cluster(ccohort)
eststo m4a: qui margins, dydx(gdp_growth_410_28_32) at(democracy_410_28_32=( 0)) post


coefplot ///
(m0,msymbol(square_hollow) offset(-0.5)) (m0a, offset(-0.5)) (m1,msymbol(square_hollow) offset(0.0)) (m1a, offset(0.0)) (m2,msymbol(square_hollow) offset(0.5)) (m2a, offset(0.5)) (m3, msymbol(square_hollow) offset(1)) (m3a, offset(1)) (m4, msymbol(square_hollow) offset(1.5)) (m4a, msymbol(circle_hollow) offset(1.5)) ,  mcolor(gray) lpattern(solid) lcolor(black) msymbol(circle_hollow) msize(medium) ciopts(color(black%50) lcolor(black%50) recast(rcap)) vertical yline(0, lcolor(black) lpattern(dash) lwidth(thin)) ylabel(-0.2(0.1)0.2, nogrid labsize(medsmall)) ytitle(" Effect of economic performance (early adulthood)", margin(small) color(black) size(medium)) graphregion(lstyle(none) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
 xlabel(-0.5 "" 0.5 "8-12" 2 "13-17" 3.5 "18-22" 5 "23-27" 6.5 "28-32" 7 "" , labsize(medsmall) nogrid) xtitle("Age cohort", margin(small) color(black) size(medium)) legend(order(4 "Autocracies" 2 "Democracies" ) region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.8) symysize(*.8) forcesize ring(0) position(11) colgap(tiny) row(1)) 
 graph save figureA3,replace



** Control for aut. regime type **
qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28  monarchy_c_1010_18_28 party_c_1010_18_28 personalist_c_1010_18_28 military_c_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
margins, dydx(gdp_growth_1010_18_28) at(democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(med) margin(small)) ///
addplot((histogram democracy_1010_18_28 if e(sample),xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save figureA4, replace

** Control regime change **
g trans=0 if democracy_1010_18_28!=.
recode trans (0=1) if democracy_1010<0.5 & democracy==1
g break=0 if democracy_1010_18_28!=.
recode break (0=1) if democracy_1010>0.5 & democracy==0
qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28  trans break gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
margins, dydx(gdp_growth_1010_18_28) at(democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(med)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(medsmall) margin(small)) ///
addplot((histogram democracy_1010_18_28 if e(sample),xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) ///
ylabel(, labsize(med) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save figureA5, replace

** Control for repression  **
qui reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28  c.v2csreprss_1010_18_28##c.democracy_1010_18_28   gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
margins, dydx(gdp_growth_1010_18_28) at(democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(medsmall) margin(small)) ///
addplot((histogram democracy_1010_18_28 if e(sample),xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save figureA6, replace

**Control performance legitimacy claims**
eststo clear
* Cohort, Age, Year, and Country FE + current economic growth *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 v2exl_legitperf_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., fe r

eststo
* Cohort, Age, Year, and Country FE + current regime *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 c.v2exl_legitperf_1010_18_28##c.democracy_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., fe r
eststo
esttab, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(*.birth_10 *.age_10 *.YEAR_DATA) eqlabels(none) nonumbers compress
esttab using tableA5.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(*.birth_10 *.age_10 *.YEAR_DATA ) eqlabels(none) nonumbers compress

**** Control current regime and growh - 10 year intervals ****
****                       								  ****
eststo clear
* Cohort, Age, Year, and Country FE + current economic growth *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 c.gdp_growth_1010##c.democracy_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., fe r

eststo
* Cohort, Age, Year, and Country FE + current regime *
xtset COUNTRY_ID
xtreg democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28  gdp_ln_1010_18_28 population_gled_ln_1010_18_28 democracy_1010 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., fe r
eststo
esttab, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(*.birth_10 *.age_10 *.YEAR_DATA) eqlabels(none) nonumbers compress
esttab using tableA6.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(*.birth_10 *.age_10 *.YEAR_DATA ) eqlabels(none) nonumbers compress



** Endurance in democracies and autocracies **
g democbest2=democbest*-1
reghdfe democbest c.gdp_growth_1010_18_28##c.age gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10  i.YEAR_DATA if age >=35 & age !=. & democracy_1010_18_28==1, absorb(COUNTRY_ID) cluster(ccohort)
eststo Democracy: margins, dydx(gdp_growth) at( age=(35 (5) 70)) post
reghdfe democbest2 c.gdp_growth_1010_18_28##c.age gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10  i.YEAR_DATA if age >=35 & age !=. & democracy_1010_18_28==0, absorb(COUNTRY_ID) cluster(ccohort)
eststo Autocracy: margins, dydx(gdp_growth) at( age=(35 (5) 70)) post

coefplot ///
(Democracy, offset(0.0) mcolor(black) lpattern(solid) lcolor(gs3) msymbol(circle_hollow) msize(medium)  ciopts(color(black) lcolor(gray))) ///
(Autocracy, offset(0.0) mcolor(black) lpattern(solid) lcolor(black) msymbol(circle) msize(medium) ciopts(color(black) lcolor(black))) ///
, ///
vertical ///
yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) ///
ylabel(-0.5(0.25)1, nogrid labsize(medsmall)) ytitle("Absolute effect of economic performance (early adulthood)", margin(small) color(black) size(medsmall)) graphregion(lstyle(none) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
xlabel(1 "35" 2 "40" 3 "45" 4 "50" 5 "55" 6 "60" 7 "65" 8 "70", labsize(medsmall) nogrid)  xtitle("Age", margin(small) color(black) size(medsmall)) ///
legend(order(4 "Autocracies" 2 "Democracies" ) region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.8) symysize(*.8) forcesize ring(0) position(11) colgap(tiny) row(1)) 
graph save figureA7, replace
capture drop democbest2

** Variation among democracies and autocracies **
*Polyarchy from V-Dem from 10th to 90th percentile*
qui reghdfe democbest c.gdp_growth_1010_18_28##c.v2x_polyarchy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., absorb(COUNTRY_ID) cluster(ccohort)

qui margins, dydx(gdp_growth_1010_18_28) at(v2x_polyarchy_1010_18_28 = (0 (0.1) 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) ) ///
ylabel(, nogrid labsize(medium)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny))  ///
 xscale(r(0 1)) ///
xtitle("Polyarchy (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(medsmall) ) ///
addplot((histogram v2x_polyarchy_1010_18_28 if e(sample),xscale(r(0 1)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2)  ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero)  axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white)  )
graph save figureA8, replace

*Effects of within-regime variation? (Table A7)*
reghdfe democbest c.gdp_growth_1010_18_28##c.v2x_polyarchy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy_1010_18_28==1 , cluster(ccohort) absorb(COUNTRY_ID)
reghdfe democbest c.gdp_growth_1010_18_28##c.v2x_polyarchy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy_1010_18_28==0 , cluster(ccohort) absorb(COUNTRY_ID)
reghdfe democbest c.gdp_growth_1010_18_28##c.v2x_libdem_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy_1010_18_28==1 , cluster(ccohort) absorb(COUNTRY_ID)
reghdfe democbest c.gdp_growth_1010_18_28##c.v2x_libdem_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy_1010_18_28==0 , cluster(ccohort) absorb(COUNTRY_ID)
reghdfe democbest c.gdp_growth_1010_18_28##c.monarchy_c_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy_1010_18_28==0 , cluster(ccohort) absorb(COUNTRY_ID)
reghdfe democbest c.gdp_growth_1010_18_28##c.party_c_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy_1010_18_28==0 , cluster(ccohort) absorb(COUNTRY_ID)
reghdfe democbest c.gdp_growth_1010_18_28##c.personalist_c_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy_1010_18_28==0 , cluster(ccohort) absorb(COUNTRY_ID)
reghdfe democbest c.gdp_growth_1010_18_28##c.military_c_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy_1010_18_28==0 , cluster(ccohort) absorb(COUNTRY_ID)

** Mixed Democratic Experiences **
//excluding middle category
reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. & democracy_1010_18_28==1 | age >=28 & age !=. & democracy_1010_18_28==0 , cluster(ccohort) absorb(COUNTRY_ID)
margins, dydx(gdp_growth_1010_18_28) at(democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(med) margin(small)) ///
addplot((histogram democracy_1010_18_28 if e(sample),xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save dem_nomiddle, replace

//seperate middle category
g cat=0 if democracy_1010_18_28!=.
recode cat (0=1) if democracy_1010_18_28>0 & democracy_1010_18_28<1
recode cat (0=2) if democracy_1010_18_28==1
reghdfe democbest c.gdp_growth_1010_18_28##i.cat gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=. , cluster(ccohort) absorb(COUNTRY_ID)
margins, dydx(gdp_growth_1010_18_28) at(cat = (0 1 2)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) recast(scatter) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1 "Both" 2"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 2.2)) ///
xtitle("Regime type (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(med) margin(small)) ///
addplot((histogram cat if e(sample),xscale(r(-0.1 2.2)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1 "Both" 2"Democracy", nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save dem_middle, replace
graph combine dem_nomiddle.gph dem_middle.gph, xsize(20) ysize(10) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) rows(1) cols(2) 
graph save figureA9,  replace

** Level of democracy during early adulthood **
reghdfe democbest c.gdp_ln_1010_18_28##c.democracy_1010_18_28  population_gled_ln_1010_18_28 if age >=28 & age !=., cluster(ccohort) absorb( i.birth_10 i.age_10 i.YEAR_DATA)

margins,  at(gdp_ln_1010_18_28= (6 (1) 11) democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(circle) msize(medium)) ciopts(color(gs10%30) lcolor(gs10%30) lwidth(none)) recastci(rarea) ///
plot2opts(mcolor(black) lpattern(solid) lcolor(black) msymbol(circle_hollow) msize(medium)) ci2opts(color(gs10%30) lcolor(gs10%30))  ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) legend(order(3 "Autocracies" 4 "Democracies") region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.6) symysize(*.6) forcesize ring(0) position(11) colgap(tiny) row(1)) ///
xlabel(6(1)11, nogrid labsize(medsmall)) ///
xtitle("Ln(GDP/cap) (early adulthood)", margin(large) size(med)) title("") ytitle("Support democracy", size(medsmall) margin(small)) ///
addplot((histogram gdp_ln_1010_18_28 if e(sample),  ///
ytitle("Support democracy", size(medsmall) margin(small)) discrete width(.5) freq yaxis(2) xlabel(6(1)12, nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 100000, nolabels noticks axis(2)) legend(order(3 "Autocracies" 4 "Democracies") region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.8) symysize(*.8) forcesize ring(0) position(11) colgap(tiny) row(1)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save figureA10, replace
   

** Using the original scale **
egen democbest2=group(democbest)

reghdfe democbest2 c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)

margins, at(gdp_growth_1010_18_28 = (-6(1)8) democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(circle) msize(medium)) ciopts(color(gs10%30) lcolor(gs10%30) lwidth(none)) recastci(rarea) ///
plot2opts(mcolor(black) lpattern(solid) lcolor(black) msymbol(circle_hollow) msize(medium)) ci2opts(color(gs10%30) lcolor(gs10%30))  ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) legend(order(3 "Autocracies" 4 "Democracies") region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.6) symysize(*.6) forcesize ring(0) position(11) colgap(tiny) row(1)) ///
xlabel(-6(1)8, nogrid labsize(medsmall)) ///
xtitle("Economic performance (early adulthood)", margin(large) size(med)) title("") ytitle("Support democracy", size(medsmall) margin(small)) ///
addplot((histogram gdp_growth_1010_18_28 if e(sample) & gdp_growth_1010_18_28>=-6 & gdp_growth_1010_18_28<=8,  ///
ytitle("Support democracy", size(medsmall) margin(small)) discrete width(.5) freq yaxis(2) xlabel(-6(1)8, nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 100000, nolabels noticks axis(2)) legend(order(3 "Autocracies" 4 "Democracies") region(lstyle(none) lcolor(white)) size(*1.2) symxsize(*.8) symysize(*.8) forcesize ring(0) position(11) colgap(tiny) row(1)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save dem2_pred, replace

reghdfe democbest2 c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  i.birth_10 i.age_10 i.YEAR_DATA if age >=28 & age !=., cluster(ccohort) absorb(COUNTRY_ID)
margins, dydx(gdp_growth_1010_18_28) at(democracy_1010_18_28 = (0 1)) level(95) asobserved 

marginsplot, ///
plotopts(mcolor(black) lpattern(solid) lcolor(black) msymbol(s) msize(medium)) ciopts(color(black)) recastci(rspike) ///
level(95) graphregion(fcolor(white) lcolor(white) margin(medium)) ///
ylabel(, nogrid labsize(medsmall)) yline(0, lcolor(gs6) lpattern(dash) lwidth(thin)) legend(off order() size(*.5) symxsize(*.1) symysize(*.1) forcesize ring(0) position(11) colgap(tiny)) plotr(m(small)) ///
xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) xscale(r(-0.1 1.1)) ///
xtitle("Regime type (early adulthood)", margin(large) size(med)) title("") ytitle("Effect of economic performance (early adulthood)", size(med) margin(small)) ///
addplot((histogram democracy_1010_18_28 if e(sample),xscale(r(-0.1 1.1)) plotr(m(vsmall)) ytitle("Effect of economic performance (early adulthood)", /// 
size(medsmall) margin(small)) discrete width(.1) freq yaxis(2) xlabel(0 "Autocracy" 1"Democracy", nogrid labsize(medsmall)) ///
ylabel(, labsize(medsmall) norescale) color(gs11%30) lcolor(gs11%8) lpattern(solid) ylabel(0 400000, nolabels noticks axis(2)) ///
ytitle("", size(zero) margin(zero) axis(2)) yscale(lstyle(none) titlegap(0) outergap(0) axis(2))))  graphregion(fcolor(white) lcolor(white) margin(small)) plotr(m(small))
graph save dem2_marg, replace

graph combine dem2_pred.gph dem2_marg.gph, xsize(20) ysize(10) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) rows(1) cols(2) 

graph save figureA11,  replace

** Handling Missing Values (Table A8-9) **
g missing_y=0
recode missing_y (0=1) if democbest==.
g missing_x=0
recode missing_x (0=1) if gdp_growth_1010_18_28==. | democracy_1010_18_28==.
drop if age<28
eststo m1: reghdfe missing_y gdp_growth_1010_18_28 democracy_1010_18_28  ,absorb(YEAR_DATA COUNTRY_ID birth_10 age_10) cluster(COUNTRY_ID)
replace democbest=democbest/100
eststo m2: reghdfe missing_x democbest , cluster(COUNTRY_ID) absorb(YEAR_DATA COUNTRY_ID birth_10 age_10)
esttab m1 m2  using tableA8.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001)  eqlabels(none) nonumbers compress
 
//export for imputation
use data_main, replace
keep democbest gdp_growth_1010_18_28 democracy_1010_18_28   birth_10 age_10 YEAR_DATA COUNTRY_ID age ccohort
keep if age>27
export delimited using "for_imputation.csv", nolabel replace
//run imputation file in R
//import imputed dataset and run main model
clear
import delimited "outdata1.csv"
replace democbest=0 if democbest<0 
replace democbest=100 if democbest>100
replace democracy_1010=1 if democracy_1010>1
replace democracy_1010=0 if democracy_1010<0
eststo m1: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28    if age >=28 & age !=. , cluster(ccohort) absorb(i.country i.birth_10 i.age_10 i.year )
clear
import delimited "outdata2.csv",
replace democbest=0 if democbest<0 
replace democbest=100 if democbest>100
replace democracy_1010=1 if democracy_1010>1
replace democracy_1010=0 if democracy_1010<0
eststo m2: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28    if age >=28 & age !=. , cluster(ccohort) absorb(i.country i.birth_10 i.age_10 i.year )
clear
import delimited "outdata3.csv",
replace democbest=0 if democbest<0 
replace democbest=100 if democbest>100
replace democracy_1010=1 if democracy_1010>1
replace democracy_1010=0 if democracy_1010<0
eststo m3: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28    if age >=28 & age !=. , cluster(ccohort) absorb(i.country i.birth_10 i.age_10 i.year )
clear
import delimited "outdata4.csv",
replace democbest=0 if democbest<0 
replace democbest=100 if democbest>100
replace democracy_1010=1 if democracy_1010>1
replace democracy_1010=0 if democracy_1010<0
eststo m4: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28    if age >=28 & age !=. , cluster(ccohort) absorb(i.country i.birth_10 i.age_10 i.year )
clear
import delimited "outdata5.csv"
replace democbest=0 if democbest<0 
replace democbest=100 if democbest>100
replace democracy_1010=1 if democracy_1010>1
replace democracy_1010=0 if democracy_1010<0
eststo m5: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28    if age >=28 & age !=. , cluster(ccohort) absorb(i.country i.birth_10 i.age_10 i.year )

esttab m1 m2 m3 m4 m5, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop() eqlabels(none) nonumbers compress

esttab m1 m2 m3 m4 m5 using tableA9.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001)  eqlabels(none) nonumbers compress
 

** Het. effects **
use data_main, replace
eststo clear

eststo m1: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & female==1, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
eststo m2: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & female==0, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
eststo m3: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & educ==1, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
eststo m4: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & educ==2, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
eststo m5: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & educ==3, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
eststo m6: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & religion==0, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
eststo m7: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & religion==1, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
eststo m8: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & religion==2, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
eststo m9: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & employment==1, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
eststo m10: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & employment==2, cluster(ccohort) absorb(COUNTRY_ID i.birth_10 i.age_10 i.YEAR_DATA)
esttab, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(gdp_ln_1010_18_28 population_gled_ln_1010_18_28) eqlabels(none) nonumbers compress

esttab using tableA10.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001) drop(gdp_ln_1010_18_28 population_gled_ln_1010_18_28) eqlabels(none) nonumbers compress

** Single-country analyses **
eststo clear
eststo m1: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 if age >=28 & age !=. & COUNTRY_DATA=="Portugal" , cluster(ccohort) absorb(i.birth_10 i.age_10 i.YEAR_DATA)
eststo m2: reghdfe democbest c.gdp_growth_1010_18_28##c.democracy_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & COUNTRY_DATA=="Poland" , cluster(ccohort) absorb(i.birth_10 i.age_10 i.YEAR_DATA)
eststo m3: reghdfe democbest c.gdp_growth_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28 if age >=28 & age !=. & COUNTRY_DATA=="South Korea" & democracy_1010_18_28==0, cluster(ccohort) absorb(i.birth_10 i.age_10 i.YEAR_DATA)
eststo m4: reghdfe democbest c.gdp_growth_1010_18_28 gdp_ln_1010_18_28 population_gled_ln_1010_18_28  if age >=28 & age !=. & COUNTRY_DATA=="Chile" & democracy_1010_18_28==1, cluster(ccohort) absorb(i.birth_10 i.age_10 i.YEAR_DATA)
esttab using tableA11.rtf, replace label b(3) se(3) se star(+ 0.1 * 0.05 ** 0.01 *** 0.001)  eqlabels(none) nonumbers compress

log close
translate results.log results.pdf
